/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * addServices.java
 *
 * Created on 9-ago-2009, 16.10.54
 */

package freimapgsoc;

import javax.jmdns.JmDNS;
import javax.swing.DefaultListModel;


/**
 *
 * @author stefanopilla
 */
public class addServices extends javax.swing.JFrame {

    /** Creates new form addServices */
    public addServices(DefaultListModel types, JmDNS jmdns) {
        initComponents();
        this.jmdns=jmdns;
        for (int i=0; i<services.length; i++){
            servicesList.addItem(services[i]);
        }
        this.types=types;
           }

    /**
	 * This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 * @return 
	 */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        servicesList = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        okButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance().getContext().getResourceMap(addServices.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setAlwaysOnTop(true);
        setName("Form"); // NOI18N
        setResizable(false);

        servicesList.setEditable(true);
        servicesList.setMaximumRowCount(15);
        servicesList.setName("servicesList"); // NOI18N
        servicesList.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                servicesListActionPerformed(evt);
            }
        });

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        okButton.setIcon(resourceMap.getIcon("okButton.icon")); // NOI18N
        okButton.setText(resourceMap.getString("okButton.text")); // NOI18N
        okButton.setName("okButton"); // NOI18N
        okButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(servicesList, javax.swing.GroupLayout.PREFERRED_SIZE, 233, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(85, 85, 85)
                        .addComponent(okButton, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel1)))
                .addContainerGap(20, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(7, 7, 7)
                .addComponent(servicesList, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(okButton)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void servicesListActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_servicesListActionPerformed
       stype=selectProtocol(servicesList.getSelectedItem().toString());        // TODO add your handling code here:
    }//GEN-LAST:event_servicesListActionPerformed

    private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
        if(stype.equals("null")){
            this.dispose();
        }
        else{
           jmdns.registerServiceType(stype+"local.");
            this.dispose();
        }
    }//GEN-LAST:event_okButtonActionPerformed



    /**
    * @param args the command line arguments
    */
   

    public String selectProtocol(String ser){
        int i=0;
        while(ser!=services[i]){
            i++;
        }
        String stype=services[i].substring(services[i].indexOf("(")+1, services[i].indexOf(")"));
        //String serviceName=services[i].substring(0, services[i].lastIndexOf("("));
        return stype;
    }


    private String services[]=new String[]{
                "iTunes Music Sharing (_daap._tcp.)",
                "iChat AV (_presence._tcp.)",
                "iChat 1.0 (_ichat._tcp.)",
                "HTTP (_http._tcp.)",
                "FTP (_ftp_._tcp.)",
                "Real Time Stream Control Protocol (_rtsp._tcp.)",
                "SubEthaEdit (_hydra._tcp.)",
                "XCode Distributed Compiler (_distcc._tcp.)",
                "iConquer (_iconquer._tcp.)",
                "VueProRenderCow (_vue4rendercow._tcp.)",
                "QMaster (_qmp._tcp.)",
                "AquaMon(_aquamon._tcp.)",
                "TiVo (_tivo_servemedia._tcp.)",
                "Airport Base Station (_airport._tcp.)",
                "Apple File Sharing (_afpovertcp._tcp.)",
                "Print Spooler (_printer._tcp.)",
                "Internet Printing Protocol (_printer._tcp.)",
                "Printer PDL Data Stream (_pdl-datastream._tcp.)",
                "Sybase Server (_sybase._tcp.)",
                "Remote AppleEvents (_eppc._tcp.)",
                "Workgroup Manager (_workstation._tcp.)",
                "Mac OS X Duplicate Suppressione (_MacOSXDupSuppress._tcp.)",
                "SSH (_ssh._tcp.)",
                "Telent (_telnet._tcp.)",
                "Trivial FTP (_tftp._udp.)",
                "Samba (_smb._tcp.)",
                "XServe RAID (_xserveraid._tcp.)",
                "Fluid Theme Server (_chfts._tcp.)",
                "NetBIOS Name Service (_netbios-ns._udp.)",
                "NetBIOS Session Service (_netbios-ssn._tcp)",
                "mDNS Update Test (_testupdate._tcp.)",
                "mDNS Large TXT Test (_testlargetxt._tcp.)",
                "mDNS Dual TXT Test (_testdualtxt._tcp.)",
                "Safari Menu (_safarimenu._tcp.)",
                "Clipboard Sharing (_clipboard._tcp.)",
                "Apple Password Server (_apple-sasl._tcp.)",
                "DO over NSSocketPort (_nssocketport._tcp.)",
                "MP3 Sushi (_mp3suchi._tcp.)",
                "iChalk (_ichalkboard._tcp.)",
                "Screen Sharing (_ssscreenshare._tcp.)",
                "iStorm (_istorm._tcp.)",
                "Project Gridlock (_chess._tcp.)",
                "ARTIS Team Task (_teamlist._tcp.)",
                "address-o-sync (_aSync._tcp.)",
                "Nicecast (_shoutcast._tcp.)",
                "Net Monitor Server (_netmonitorserver._tcp.)",
                "Net Monitor Anti-Piracy Service (_ecbyesfsgksc._tcp.)",
                "ClipboardSharing (_cliboardsharing._tcp.)",
                "PostegreSQL Server (_postgressql._tcp.)",
                "Hotwayd (_hotwayd._tcp.)",
                "CVS PServer (_cvspserver._tcp.)",
                "POP3 (_pop3._tcp.)",
                "RendezvousPong (_rendezvousPong._tcp.)",
                "imap4 over TLS/SSL (_imaps._tcp.)",
                "IMAP (_imap._tcp.)",
                "pop3 over TSL/SSL (_pop3s._tcp.)",
                "BootStrap Protocol Server (_bootps._udp.)",
                "Shell (_shell._tcp.)",
                "Remote Login a la telnet (_login._tcp.)",
                "The Cheat (_cheat._tcp.)",
                "MacFOH Remote (_macfoh-remote._tcp.)",
                "Teleport (_teleport._udp.)",
                "InterBase Database Remote Protocol (_gds_db._tcp.)",
                "iPhoto Picture Shatring (_dpap._tcp.)",
                "Authentication Service (_auth._tcp.)",
                "TI Navigator (_tinavigator._tcp.)",
                "TI Connect Manager (tieducationalhandhelddevice._tcp.)",
                "MenuTunes Sharing (_mttp._tcp.)",
                "Spin Crisis (_spincrisis._tcp.)",
                "MYOB AccountEdge (_accountedge._tcp.)",
                "Apple Applicaziont Engineering Services (_aecoretech._tcp.)",
                "Bug Of Unusual Strategy Games (_bousg._tcp.)",
                "Now Contact (_contactserver._tcp.)",
                "CyTV (_cytv._tcp.)",
                "EyeHome (_difi._tcp.)",
                "Earphoria (_earphoria._tcp.)",
                "Interactive Room Software Infrastructure (_eheap._tcp.)",
                "DataEnvoy (_embrace._tcp.)",
                "FaceSpan (_facespoan._tcp.)",
                "Fjork (_fjork._tcp.)",
                "File Maker Pro (_fmpro-internal._tcp.)",
                "Crocodile FTP Server (_ftpcroco._tcp.)",
                "SnapMail (_gbs-smp._tcp.)",
                "SnapTalk (_gbs-stp._tcp.)",
                "Roxio ToastAnyWhere Recorder Sharing (_grillezvous._tcp.)",
                "H.323 Streaming (_h323._tcp.)",
                "Image Capture Networking (_ica-networking._tcp.)",
                "iMidi (_imidi._tcp.)",
                "iSparx (_isparx._tcp.)",
                "iShare (_ishare._tcp.)",
                "iWork Server (_iwork._tcp.)",
                "Liason (_liaison._tcp.)",
                "LonTalk over IP (_lontalk._tcp.)",
                "Echelon LNS Remote Client (_lonworks._tcp.)",
                "MoneyWorks Gols/DataCentre (_moneyworks._tcp.)",
                "Network Clipboard Broadcasts (_ncbroadcast._tcp.)",
                "Network Clipboard Dricet Transfers (_ncdirect._tcp.)",
                "Network Clipboard Sync Server (_ncsyncserver._tcp)",
                "Escale (_newton-dock._tcp.)",
                "Network File System (_nfs._tcp.)",
                "OmniWeb Bookmark Sharing (_omni-bookmark._tcp.)",
                "OpenBase SQL (_openbase._tcp.)",
                "Parallel Operation and Control Heuristic (_poch._tcp.)",
                "Pop-Pop (_pop_2_ambrosia._tcp.)",
                "Picture Transfer Protocol (_ptp._tcp.)",
                "Remote I/O USB Printer (_riousbprint._tcp.)",
                "Remote Frame Buffer (_rfb._tcp.)",
                "Scone (_scone._tcp.)",
                "Speed Download (_sdsharing._tcp.)",
                "seeCard (_seeCard._tcp.)",
                "Shout (_shout._tcp.)",
                "Simple Obkect Access Protocol (_soap._tcp.)",
                "launchTunes (_spl-itunes._tcp.)",
                "netTunes (_spr-itunes._tcp.)",
                "Strateges (_strateges._tcp.)",
                "Sun Grid Engine (Executione Host) (_sge-exec._tcp.)",
                "Sun Grid Engine (Master) (_sge-qmaster._tcp.)",
                "Sticky Notes (_stickynotes._tcp.)",
                "Synchroniza! Pro X (_sxqdea._tcp.)",
                "Power Card (rce._tcp.)",
                "Universal Plug and Play (_upnp._tcp.)",
                "uTest (_utest._tcp.)",
                "WebDAV (_webdav._tcp.)",
                "Whamb (_whamb._tcp.)",
                "Web Services (_ws._tcp.)",
                "XServe RAID Synchronization (_xsync._tcp.)",
                "SliMP3 Server Command-Line Interface (_slimdevices_slimp3_cli._tcp.)",
                "SliMP3 Server Web Interface (_slimdevices_slimp3_http._tcp.)",
                "Wired Server (_wired._tcp.)",
                "Now Up-to-Date (_eventserver._tcp.)",
                "Remote Process Exeution (_exec._tcp.)",
                "Xgrid Technology Preview (_beep._tcp.)",
                "iSpQ VideoChat (_ispq-vc._tcp.)",
                "Animo License Server (_animolmd._tcp.)",
                "Animo Batch Server (_animobserver._tcp.)",
                "Goban (_ch-sente-go-server._tcp.)",
                "Peer-to-peer Chat (_p2pchat._udp.)",
                "SubEthaEdit 2 (_see._tcp.)",
                "AirTunes (_raop._tcp.)",
                "Apple Remote Desktop (_net-assistant._udp.)",
                "AccesOne (_accessone._tcp.)",
                "ActionItems (_actionitems._tcp.)",
                "Address-O-Matic (_addressbook._tcp.)",
                "BuildForge Agent (_bfagent._tcp.)",
                "Big Bang Chess (_bigbangchess._tcp.)",
                "Backup Simplicity (_bsqdea._tcp.)",
                "Published Colletion Object (_colletcion._tcp.)",
                "Vortimac Dossier Protocol (_dossier._tcp.)",
                "ebXML Messaging (_ebms._tcp.)",
                "FAXstf (_faxstfx._tcp.)",
                "Fish (_fish._tcp.)",
                "FontAgent Pro (_fontagentnode._tcp.)",
                "Published iFolder (_ifolder._tcp.)",
                "iLynX (_ilynx._tcp.)",
                "IP Broadcaster (_ipbroadcaster._tcp.)",
                "iSticky (_isticky._tcp.)",
                "Lan2P P2P Network Protocol (_lan2p._tcp.)",
                "Mac Minder (_macminder._tcp.)",
                "OD4Contact (_odabsharing._tcp.)",
                "Quinn Game Server (_quinn._tcp.)",
                "RealPlayer Shared Favorites (_realplayfavs._tcp.)",
                "RubyGems GemServer (_rubygems._tcp.)",
                "Salling Clicker (_sallingclicker._tcp.)",
                "serendiPd Shared Patches for Pure Data (_serendipd._tcp.)",
                "Mac OS X Server Admin (_servermgr._tcp.)",
                "TI Connect Manager (_ticonnectmgr._tcp.)",
                "Virtual Object System (_vos._tcp.)",
                "Roku Cascade Wormhole Protocol (_wormhole._tcp.)",
                "Novell Collaboration WorkGroup (_workgroup._tcp.)",
                "xTime Project (_xtsharpro._tcp.)",
                "World Book Encyclopedia (_WorldBook2004ST._tcp.)",
                "NetNewsWire (_feed-sharing._tcp.)",
                "SFTP (_sftp-ssh._tcp.)",
                "AirProjector (_airprojector._tcp)",
                "Apple Software Restore (_asr._tcp.)",
                "Axis Video Cameras (_axis-video._tcp.)",
                "Big Bang Mancala (_bigbangmangala._tcp.)",
                "Conferencing Protocol (_cuseeme._udp.)",
                "CodeWarrior HTI Xscale PowerTAP (_cw-codetap._tcp.)",
                "CodeWarrior HTI DPI PowerTAP (_cw-dpitap._tcp.)",
                "CodeWarrior HTI OnCE PowerTAP (_cw-oncetap._tcp.)",
                "CodeWarrior HTI COP PowerTAP (_cw-powertap._tcp.)",
                "iTunes Digital Audio Control Protocol (_dacp._tcp.)",
                "DNS Long-Lived Queries (_dns-llq._udp.)",
                "DNS Dynamic Update Service (_dns-update._udp.)",
                "Domain Name Server (_domain._udp.)",
                "Home Media Control Protocol (_hmcp._tcp.)",
                "Inter Asterisk eXchange (VoIP) (_iax._udp.)",
                "Idle Hands iHouse Protocol (_ihouse._tcp.)",
                "Jedit X (_jedit._tcp.)",
                "Kerberos (_kerberos._tcp.)",
                "Kerberos Administrator (_kermeros-adm._tcp.)",
                "Logic Pro Distributed Audio (_logicnode._udp.)",
                "Network Time Protocol (_ntp._tcp.)",
                "PTNetPro Service (_prnetprosrv2._tcp.)",
                "ARTvps RenderDrive/PURE Renderer Protocol (_renderpipe._tcp.)",
                "Rsync (_rsync._tcp.)",
                "Schick (_schick._tcp.)",
                "Session Initiation Protocol (VoIP) (_sip._udp.)",
                "Synchronize! X Plus 2.0 (_syncqdea._tcp.)",
                "Timbuktu (_timbutku._tcp.)",
                "XMPP Cient Connection (_xmpp-client._tcp.)",
                "XMPP Server Connection (_xmpp-server._tcp.)",
                "xTime License (_xtimelicense._tcp.)",
                "XUL over HTTP (_xul-http._tcp.)",
                "Big Bang Backgammon (_bigbangbackgammon._tcp.)",
                "Big Bang Checkers (_bigbangcheckers._tcp.)",
                "Skype (_skype._tcp.)"

        };

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JButton okButton;
    private javax.swing.JComboBox servicesList;
    // End of variables declaration//GEN-END:variables
    public String stype="null";
    public DefaultListModel types;
    public JmDNS jmdns;
}
